package org.lgiavedoni.android.franq.core.question.imp;

import java.util.ArrayList;

import org.lgiavedoni.android.franq.core.message.MessageIn;
import org.lgiavedoni.android.franq.core.question.Question;
import org.lgiavedoni.android.franq.util.booleanU.BooleanUtil;
import org.lgiavedoni.android.franq.util.booleanU.UndecodedBoolean;
import org.lgiavedoni.android.franq.util.phone.voice.VoiceReceiver;
import org.lgiavedoni.android.franq.util.phone.voice.VoiceRecognition;

public class YesOrNoQuestion extends Question<Boolean> implements VoiceReceiver {

	private final String text;

	public YesOrNoQuestion(String text) {
		this.text = text;
		VoiceRecognition.recognizeSpeech(this);
	}

	@Override
	public String getQuestionText() {
		return text + " [Yes - No]";
	}

	@Override
	public boolean process(MessageIn messageIn) {
		Boolean result;
		try {
			result = BooleanUtil.decode(messageIn.getText());
			setResult(result);
			return true;
		} catch (UndecodedBoolean e) {
			return false;
		}
	}

	@Override
	public boolean equals(Question q) {
		return false;
	}

	@Override
	public void result(ArrayList<String> recognize) {
		// FIXME
		if (recognize != null && recognize.size() > 0) {
			process(MessageIn.create(null, recognize.get(0)));
		}
	}

}
